#include <iostream>
#include <memory>
#include <functional>

#include "TcpClient.hpp"

#include "Thread.hpp"

using namespace ThreadModule;

/*多线程版本*/
int main(int argc, char* argv[])
{
    if(argc != 3)
    {
        std::cerr << "Usage: " << argv[0] << " server-ip server-port" << std::endl;
        exit(1);
    }

    std::string ip = argv[1];
    uint16_t port = std::stoi(argv[2]);

    std::unique_ptr<TcpClient> tcsv = std::make_unique<TcpClient>(ip, port);

    Thread send("send-thread", std::bind(&TcpClient::sendMsg,tcsv.get(), std::placeholders::_1));
    Thread recv("recv-thread", std::bind(&TcpClient::recvMsg,tcsv.get(), std::placeholders::_1));

    send.start();
    recv.start();

    send.join();
    recv.join();
    return 0;
}

/*单进程版*/
// int main(int argc, char* argv[])
// {
//     if(argc != 3)
//     {
//         std::cerr << "Usage: " << argv[0] << " server-ip server-port" << std::endl;
//         exit(1);
//     }

//     std::string ip = argv[1];
//     uint16_t port = std::stoi(argv[2]);

//     std::unique_ptr<TcpClient> tcsv = std::make_unique<TcpClient>(ip, port);
//     tcsv->Loop();
    
//     return 0;
// }